package com.feeyo.monitor.service.imp;

import com.feeyo.monitor.utils.UserAlreadyExistException;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.feeyo.monitor.domain.User;
import com.feeyo.monitor.enumeration.AlarmType;
import com.feeyo.monitor.mapper.UserMapper;
import com.feeyo.monitor.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImp implements UserService {
	
	@Autowired
	UserMapper userMapper;

	@Override
	public int insert(User record) {
		//Page page = PageHelper.startPage(0, 10);
		return userMapper.insert(record);
	}

    @Override
    public int insertSelective(User record) {
        return userMapper.insertSelective(record);
    }

    @Override
	public User selectByPrimaryKey(String id) {
		return userMapper.selectByPrimaryKey(id);
	}

    @Override
    public int updateDeleteStatus(String id) {
        return userMapper.updateDeleteStatus(id);
    }

    @Override
	public List<Map> login(Map param){
		return userMapper.selectByLogin(param);
	}


    @Override
    public List<Map> tokenLogin(String token) {
        return userMapper.selectByToken(token);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updatePassword(Map param) {
        return userMapper.updatePassword(param);
    }

    @Override
    public List<Map> selectByUserName(String userName) {
        return userMapper.selectByUserName(userName);
    }

    @Override
    public PageInfo selectByPage(Map param, int pageNumber, int pageSize) {
        Page<Map> page = PageHelper.startPage(pageNumber, pageSize);
        List<Map> result = userMapper.selectByPage(param);
        PageInfo pi = new PageInfo(result);
        return pi;
    }

    @Override
    public PageInfo selectByUserAndPage(Map param, int pageNumber, int pageSize) {
        Page<Map> page = PageHelper.startPage(pageNumber, pageSize);
        List<Map> result = userMapper.selectByUserAndPage(param);
        PageInfo pi = new PageInfo(result);
        return pi;
    }

}
